using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

public class GGFormat
{
	public static string ScoreNameFormat(string name)
	{
		return FirstName(name).ToUpper();
	}

	public static string FormatRank(int rank)
	{
		switch (rank)
		{
		case 0:
			return rank.ToString();
		case 1:
			return "1st";
		case 2:
			return "2nd";
		case 3:
			return "3rd";
		default:
			return rank + "th";
		}
	}

	public static string FirstLetterToUpper(string str)
	{
		if (str == null)
		{
			return null;
		}
		if (str.Length > 1)
		{
			return char.ToUpper(str[0]) + str.Substring(1);
		}
		return str.ToUpper();
	}

	public static string FirstName(string name)
	{
		if (name == null)
		{
			return string.Empty;
		}
		name = name.Trim();
		string[] array = name.Split(' ');
		if (array.Length > 0)
		{
			return array[0];
		}
		return name;
	}

	public static string FormatText(string text)
	{
		text = text.Replace("[name]", FirstLetterToUpper(GGPlayerSettings.instance.GetName()));
		return text;
	}

	public static string SingularPlural(string singular, string plural, int number)
	{
		return (number != 1) ? plural : singular;
	}

	public static string IndexName(int index)
	{
		return index.ToString("D5");
	}

	public static string FormatWinnings(int winnings, int minForM = 1000000, int minForK = 1000)
	{
		if (winnings >= minForM)
		{
			return winnings / 1000000 + "M";
		}
		if (winnings >= minForK)
		{
			return winnings / 1000 + "k";
		}
		return winnings.ToString();
	}

	public static string RandomFrom(params string[] variants)
	{
		return variants[UnityEngine.Random.Range(0, variants.Length) % variants.Length];
	}

	public static string FormatPrice(int price, bool rem = false)
	{
		if (price >= 1000000)
		{
			string text = ((!rem) ? (price / 1000000).ToString() : (price / 1000000).ToString("D3"));
			text += " ";
			int num = price % 1000000;
			if (num >= 1000)
			{
				return text + FormatPrice(num, true);
			}
			if (num % 1000 > 0)
			{
				return text + "000 " + FormatPrice(num % 1000, true);
			}
			return text + "000 000";
		}
		if (price >= 1000)
		{
			string text2 = ((!rem) ? (price / 1000).ToString() : (price / 1000).ToString("D3"));
			text2 = text2 + " " + (price % 1000).ToString("D3");
			while (price.ToString().Length >= text2.Length)
			{
				text2 += "0";
			}
			return text2;
		}
		return (!rem) ? price.ToString() : price.ToString("D3");
	}

	public static string FormatScore(int price, bool rem = false)
	{
		if (price >= 1000000)
		{
			string text = ((!rem) ? (price / 1000000).ToString() : (price / 1000000).ToString("D3"));
			text += ",";
			int num = price % 1000000;
			if (num >= 1000)
			{
				return text + FormatPrice(num, true);
			}
			if (num % 1000 > 0)
			{
				return text + "000," + FormatPrice(num % 1000, true);
			}
			return text + "000,000";
		}
		if (price >= 1000)
		{
			string text2 = ((!rem) ? (price / 1000).ToString() : (price / 1000).ToString("D3"));
			text2 = text2 + "," + (price % 1000).ToString("D3");
			while (price.ToString().Length >= text2.Length)
			{
				text2 += "0";
			}
			return text2;
		}
		return (!rem) ? price.ToString() : price.ToString("D3");
	}

	public static float WinPercent(int wins, int loses)
	{
		int num = wins + loses;
		if (num == 0)
		{
			return 0f;
		}
		return (float)wins / (float)num;
	}

	public static string FormatPercent(float p)
	{
		return ((int)(p * 100f)).ToString();
	}

	public static string Implode(IEnumerable<string> list, string glue)
	{
		StringBuilder stringBuilder = new StringBuilder();
		foreach (string item in list)
		{
			if (stringBuilder.Length > 0)
			{
				stringBuilder.Append(glue);
			}
			stringBuilder.Append(item);
		}
		return stringBuilder.ToString();
	}

	public static string FormatTime(int time)
	{
		if (time < 10)
		{
			return "0" + time;
		}
		return time.ToString();
	}

	public static string FormatTimeSpan(TimeSpan span)
	{
		string text = string.Empty;
		if (span.TotalDays >= 1.0)
		{
			text = text + FormatTime(span.Days) + ":";
		}
		if (span.TotalHours >= 1.0)
		{
			text = text + FormatTime(span.Hours) + ":";
		}
		return text + FormatTime(span.Minutes) + ":" + FormatTime(span.Seconds);
	}

	public static string FormatTimeSpanHuman(TimeSpan span, string hours = "h", string minutes = "m", string seconds = "s", bool useAnd = false)
	{
		string text = string.Empty;
		string text2 = "d";
		if (span.Days > 0)
		{
			string text3 = text;
			text = text3 + span.Days + string.Empty + text2 + " ";
		}
		if (span.Hours > 0)
		{
			string text3 = text;
			text = text3 + span.Hours + string.Empty + hours + " ";
		}
		if (span.Minutes > 0)
		{
			string text3 = text;
			text = text3 + span.Minutes + string.Empty + minutes + " ";
		}
		if (span.Seconds > 0)
		{
			if (text != string.Empty && useAnd)
			{
				text += "and ";
			}
			string text3 = text;
			text = text3 + span.Seconds + string.Empty + seconds;
		}
		return text;
	}
}
